package org.zlb.netty.server.udp;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;

public class ChinesProverServer {

    private int port;
    
    public ChinesProverServer(int port) {
        this.port = port;
    }
    
    public void run() throws Exception {
        EventLoopGroup group = new NioEventLoopGroup();
        try {
            Bootstrap b = new Bootstrap();
            b.group(group)
             .channel(NioDatagramChannel.class)
             .handler(new ChinesProverServerHandler())
             .option(ChannelOption.SO_BROADCAST, true);
    
            ChannelFuture f = b.bind(port).sync();
            System.out.println("服务端启动成功，端口:"+port);
            f.channel().closeFuture().await();
        } finally {
            group.shutdownGracefully();
        }
    }

}
